{% extends "base.html" %}

{% block body %}
  {% if next or previous %}
    <div class="nav">
      {% if previous %}
      <a class="prev" href="?page={{page|add:-1}}">Previous page</a>
      {% endif %}
      -
      {% if next %}
      <a class="next" href="?page={{page|add:1}}">Next page</a>
      {% endif %}
    </div>
  {% endif %}

  <table class="review">
  {% for entry in entries %}
  <tr class="{% cycle "odd" "even"%}">
    <td class="contest">
      {{entry.contest.name}}
      <br /><img src='/contestimage/{{entry.contest.image.key.id}}'>
      </td>
    <td class="text">
        <p>{{entry.top}}</p><hr />
        <p>{{entry.middle}}</p><hr />
        <p>{{entry.bottom}}</p></td>
    <td class="info">
      {{entry.creation_time|DisplayDate}}
      <br />{{entry.creator}}
      <br /><input type="checkbox" class="check-disabled" data-id="{{entry.key.id}}" id="disabled-{{entry.key.id}}" {{entry.disabled|yesno:"checked,"}}><label for="disabled-{{entry.key.id}}">Disabled</label>
       </td>
  </tr>
  {% endfor %}
  </table>

  {% if next or previous %}
    <div class="nav">
      {% if previous %}
      <a class="prev" href="?page={{page|add:-1}}">Previous page</a>
      {% endif %}
      {% if next %}
      <a class="next" href="?page={{page|add:1}}">Next page</a>
      {% endif %}
      <p>-</p>
    </div>
  {% endif %}

  <script>
$(function() {
  $('.review').on('click', 'input.check-disabled', function(e) {
    var id = $(this).data('id');
    var disabled = $(this).attr('checked') === 'checked';
    $.ajax({
      url: '/admin/update/' + id,
      type: 'POST',
      data: { disabled: disabled },
      dataType: 'text',
      error: function(xhr, status, err) { alert('update failed: ' + status); }
    });
  });
});
  </script>
{% endblock %}
